clear all
clear matrix
set more off
set linesize 255
pause on
version 15

** This will be called from the top level of the entire replication
global CODE_DIR = "01Code/emissions"

global CEMS_DATA_IN = "00RawData/cems"
global BASELINE_DATA_IN = "00RawData/baseline"
global BASELINE_DATA_OUT = "02DataPipeline/baseline"
global EMISSIONS_DATA_IN = "00RawData/emissions"
global IMPUTATION_DATA_OUT = "02DataPipeline/emissions/imputation"
global EMISSIONS_DATA_OUT = "02DataPipeline/emissions"

global EMISSIONS_TABS="03Output/tables"
global EMISSIONS_FIGS="03Output/figures"

** We use a conversion rate of USD 1 to INR 70, as of 2 Jan 2019, 
** Source: The Fed (https://www.federalreserve.gov/releases/h10/20190107/)
global USD2INR=70

********************************************************************************

* Conduct pollution imputation
do "$CODE_DIR/imputation/2. Create PM Mass (Stack-week).do"
do "$CODE_DIR/imputation/3a. Create PM Mass (Stack-Month, Plant-Day).do"
do "$CODE_DIR/imputation/3a. Create PM Mass (Stack-Month, Plant-Month).do"
do "$CODE_DIR/imputation/3a. Create PM Mass (Stack-Month, Plant-Period).do"
do "$CODE_DIR/imputation/3b. Create PM Mass (Stack-Experiment, Plant-Month).do"
do "$CODE_DIR/imputation/3b. Create PM Mass (Stack-Experiment, Plant-Period).do"
do "$CODE_DIR/imputation/4. Create PM Mass (Treatment-Month, Plant-Month).do"
do "$CODE_DIR/imputation/4. Create PM Mass (Treatment-Month, Plant-Period).do"
do "$CODE_DIR/imputation/6. Create PM Mass (MOC Rule).do"


* Clean baseline covariates
do "$CODE_DIR/clean_baseline_covariates.do"

* Construct analysis panels for each imputation rule
do "$CODE_DIR/construct_analysis_panel.do" 0
do "$CODE_DIR/construct_analysis_panel.do" A
do "$CODE_DIR/construct_analysis_panel.do" B
do "$CODE_DIR/construct_analysis_panel.do" M

* Create a data set of emissions based on different imputation rules
do "$CODE_DIR/combine_emissions_rules.do"

* Construct a data set of potential maximum emissions
do "$CODE_DIR/compute_potential_max_emissions.do"

************** Create scheme **************
grstyle init
grstyle yesno draw_major_hgrid no
grstyle yesno draw_major_vgrid yes
grstyle linepattern major_grid solid

* Table 1 and Table A4
* Make ETS baseline balance table
do "$CODE_DIR/make_balance_table_new.do"

* Table F3
* Make ETS baseline balance table for reporting above/below median
do "$CODE_DIR/make_balance_table_reporting_split.do"

* Figure B1
* Plot ETS baseline emissions distribution
do "$CODE_DIR/plot_emissions_distribution.do" 

* Figure 5, Figure C2 and Figure C3
* Plot CEMS data availability and emissions time series
do "$CODE_DIR/plot_emissions_time_series.do" 

* Table 3 and Table F5
* Make regression table of treatment effect on PM
do "$CODE_DIR/make_regression_table.do"

* Table F6 
* Make regression table of treatment effect on PM interacted with covid
do "$CODE_DIR/make_regression_table_covid_inter.do"

* Table F8
* Make regression table of treatment effect on PM interacted with device type
do "$CODE_DIR/make_regression_table_device_fe.do"

* Table C1 and Figure C4
do "$CODE_DIR/compare_imputation_rules.do"

* Table C3
do "$CODE_DIR/make_effect_of_cems_table.do"
